package com.ps.service.setting.imp;

import org.springframework.beans.factory.annotation.Autowired;

import com.ps.dao.BaseDaoSupport;
import com.ps.dao.dept.DepartmentDAO;
import com.ps.dao.person.EmployeeDAO;
import com.ps.dao.setting.AreaDAO;
import com.ps.entity.Result;
import com.ps.entity.Status;
import com.ps.pojo.setting.Area;
import com.ps.service.BaseServiceSupport;
import com.ps.service.setting.AreaService;
import com.ps.util.Kit;
import com.ps.util.R;

public class AreaServiceImp extends BaseServiceSupport<Area> implements
		AreaService {
    @Autowired 
    private AreaDAO areaDao;
    
    @Autowired 
    private DepartmentDAO departmentDAO;
    
    @Autowired 
    private EmployeeDAO employeeDAO;    
    
	@Override
	public BaseDaoSupport<Area> getBaseDao() {
		
		return areaDao;
	}

	@Override
	public Result delete(Integer id) {
		if (departmentDAO.getCountByProperty(DepartmentDAO.AREA_ID, id) == 0 
				&& employeeDAO.getCountByProperty(EmployeeDAO.JURISDICTIONS, id) == 0) {
			return super.delete(id);
		} else  {
			Result result = Kit.createResult();
			result.getStatus().setCode(Status.FAIL);
			result.getStatus().setMessage(R.string.getProperty("no_del_area_cited"));
			return result;
		}
		
		
	}

	
}
